//
//  leftTitleRightContentView.m
//  jiaKaoZhuShou
//
//  Created by 金艺社 on 2018/6/14.
//  Copyright © 2018年 金艺社. All rights reserved.
//

#import "leftTitleRightContentView.h"

@implementation leftTitleRightContentView  {
    NSString *lasttimeValue;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        lasttimeValue = @"";
        self.backgroundColor = [UIColor custom_color:@"#FFFFFF"];
        [self addSubview:[UILabel new]];
        [self addSubview:[UITextField new]];
    }
    return self;
}
- (void)setTitle:(NSString *)title font:(CGFloat)font titleColor:(NSString *)colorStr layout:(NSArray *)layoutAry {
    UILabel *lab = (UILabel *)self.subviews.firstObject;
    lab.text = title;
    lab.font = [UIFont systemFontOfSize:14];
    lab.textColor = [UIColor custom_color:colorStr];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(layoutAry[0]);
        make.top.equalTo(layoutAry[1]);
    }];
}
- (void)setPlaceholder:(NSString *)placeholder font:(CGFloat)font layout:(NSArray *)layoutAry {
    UITextField *textFile = (UITextField *)self.subviews.lastObject;
    textFile.delegate = self;
    textFile.placeholder = placeholder;
    textFile.font = [UIFont systemFontOfSize:14];
    [textFile mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(layoutAry[0]);
        make.top.mas_equalTo(layoutAry[1]);
    }];
    self.content_tf = textFile;
}
#pragma mark --- textfileDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
    if ([textField.text isEqualToString:@""] && ![lasttimeValue isEqualToString:@""]) {
        lasttimeValue = @"";
        self.textChangeBlock(NO);
    }else if(![textField.text isEqualToString:lasttimeValue] && [lasttimeValue isEqualToString:@""]) {
        lasttimeValue = textField.text;
        self.textChangeBlock(YES);
    }
}
@end
